package com.czp.mall.feign.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.czp.mall.feign.pojo.Item;
import com.czp.mall.feign.service.ItemServiceClient;
import com.czp.mall.feign.service.ItemServiceFeignHystrixClient;
import com.czp.mall.feign.service.ItemServiceFeignHystrixDisableClient;


@RestController
public class ItemController {

	
	// @Autowired
	// private ItemServiceClient itemServiceClient;
	
	@Autowired
	private ItemServiceFeignHystrixClient itemServiceFeignHystrixClient; // 测试feign中使用hystrix
	
	@Autowired
	private ItemServiceFeignHystrixDisableClient itemServiceFeignHystrixDisableClient;
	
	@GetMapping(value = "/order/{id}",produces = {"application/json;charset=UTF-8"})
	public Item queryOrderById(@PathVariable(name = "id") String id) {
		
		//return itemServiceClient.queryItemById(Long.valueOf(id));
		Item item = itemServiceFeignHystrixClient.queryItemById(Long.valueOf(id));
//		System.out.println(item.toString());
		return item;
		
	}
	
	@GetMapping(value = "/item/{id}",produces = {"application/json;charset=UTF-8"})
	public Item queryItemById(@PathVariable(name = "id") String id) {
		
		Item item = itemServiceFeignHystrixDisableClient.queryItemById(Long.valueOf(id));

		return item;
		
	}
	
	
}
